import {
    Image,
    ImageSourcePropType,
    Dimensions,
} from "react-native";
import React, { useEffect, useState } from "react";

interface ImageListAutoPropsType {
    imgUrl: String;
    width?: string | number;
    style?: Object;
    
}

const ImageListAuto = ({ imgUrl, width, style }: ImageListAutoPropsType) => {
    const [imageRealSize, setImageRealSize] = useState({ height: 0 });

    useEffect(() => {
        Image.getSize(String(imgUrl), (width, height) => {
            setImageRealSize({
                height: Math.floor((Dimensions.get("window").width * height) / width),
            });
        });
    }, []);

    return (
        <Image
            style={{ width, ...imageRealSize, ...style }}
            resizeMethod={'scale'}
            source={
                {
                    uri: imgUrl,
                } as ImageSourcePropType
            }
        />
    );
};

export default ImageListAuto;
